<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>http://www.xinyues.com</title>
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<script src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="background: #f2f4f8;">

	<div align="center">

		<h2>
			欢迎登录
		</h2>
		<hr>
		<table style="border-collapse: separate; border-spacing: 0px 10px;">
			<tr>
				<td><span id="errorTips" style="color: red"></span></td>
			</tr>
			<tr>
				<td>账号： <input class="easyui-textbox" prompt="Username"
					id="username" iconWidth="28">
				</td>
			</tr>

			<tr>
				<td>密码： <input class="easyui-passwordbox" prompt="Password"
					id="password" iconWidth="28">
				</td>
			</tr>
			<tr align="center">
				<td><a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="submitForm()">--登陆--</a></td>&nbsp;
				<td>
					<a href="/api/account/register" class="easyui-linkbutton">--注册--</a>
				</td>
				<td>
					<a href="/api/account/reset" class="easyui-linkbutton">--忘记密码?--</a>
				</td>
			</tr>
		</table>
	</div>

</body>
<script type="text/javascript">
	function postAjax(url, json, success) {
		$.ajax({
			type : "POST",
			url : url,
			data : JSON.stringify(json),
			dataType : "json",
			contentType : "application/json",
			success : function(data) {
				if (data.code == 0) {
					success(data);
				} else {
					alert("服务器异常,请联系开发者");
				}
			},
			error : function(data) {
				alert(url + "请求错误：" + JSON.stringify(data));
			}
		});
	}


	function submitForm() {
		$("#errorTips").html("");
		var username = $("#username").val();
		var password = $("#password").val();
		//var url = "/api/account/login";
		var json = {
			"username" : username,
			"password" : password
		};
		$.ajax({
			type: "GET",
			url: '/api/account/login/'+json.username+'/'+json.password,
			dataType: "JSON",
			success : function (res) {
			    //alert(res.code);

                if (res.code == 100) {
                    var authUrl = "/api/account/authen";
                    var param = {};
                    postAjax(
                        authUrl,
                        param,
                        function(data) {
                            if (data.code == 0) {
                                window.location.href = "/api/account/index2";
                            } else {
                                $("#errorTips").html(data.msg);
                            }
                        });
                } else {
                    $("#errorTips").text('账号或密码不正确');
                }

            }
		});
	}
</script>
</html>